package com.los;

import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @program: java8
 * @description: 数字流
 * 减少内存占用
 * @author: Yujuan
 * @create: 2018-06-14 14:12
 **/
public class NumericStream {
    public static void main(String[] args) {
        Stream<Integer> integerStream= Arrays.stream(new Integer[]{1,2,3,4,5,6,7,8,9});

//        Integer result=integerStream.filter(integer -> integer.intValue()>3).reduce(0,Integer::sum);
//        System.out.println(result);

//        IntStream intStream=integerStream.mapToInt(Integer::intValue).filter(i -> i>3);
//        System.out.println(intStream.sum());

        int a=9;
//        IntStream intStream=IntStream.rangeClosed(1,100).filter(b->Math.sqrt(a*a+b*b)%1==0);
//
//        intStream.forEach(System.out::println);
       IntStream.rangeClosed(1,100).filter(b->Math.sqrt(a*a+b*b)%1==0).boxed()
               .map(b->new int[]{a,b, (int) Math.sqrt(a*a+b*b)})
                .forEach(r-> System.out.println(r[0]+"&&&"+r[1]+"&&&"+r[2]));

        IntStream.rangeClosed(1,100).filter(b->Math.sqrt(a*a+b*b)%1==0)
                .mapToObj(b->new int[]{a,b, (int) Math.sqrt(a*a+b*b)})
                .forEach(r-> System.out.println(r[0]+"&&&"+r[1]+"&&&"+r[2]));

    }
}
